home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / comm / net / AMarquee1_43.lha / AMarquee / examples / amarqueedebug.c < prev    next >
C/C++ Source or Header  |  1997-04-28  |  6KB  |  168 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <clib/AMarquee_protos.h>
  11.  
  12. #include <pragmas/AMarquee_pragmas.h>
  13.  
  14. struct Library * AMarqueeBase = NULL;
  15. struct QSession * session     = NULL;
  16.  
  17. /* Takes user input until blank line is typed */
  18. void ProcessDebugCommands(struct QSession * session)
  19. {
  20.   while(1)
  21.   {
  22.    char debugline[500] = "\0\0\0\0\0\0\0\0";
  23.    char * keyword, * data;
  24.    ULONG dataLen = 0L;
  25.    LONG res;
  26.    
  27.    printf("Enter your debug command now: "); fflush(stdout);
  28.    gets(debugline);
  29.   
  30.    keyword = &debugline[2];
  31.    if (data = strchr(keyword,'='))
  32.    {
  33.      *data = '\0';  /* terminate the keyword */
  34.      data++;
  35.      dataLen = strlen(data)+1;
  36.    }
  37.    switch((int)(debugline[0]))
  38.    {
  39.      case '\0': res=QGo(session,0L);                           break;
  40.      case 'A':  res=QSetMessageAccessOp(session, keyword, -1); break;
  41.      case 'm':  res=QMessageOp(session, keyword, data, dataLen); break;
  42.      case 'a':  res=QSetAccessOp(session, keyword);          break;
  43.      case 's':  res=QSetOp(session, keyword, data, dataLen); break;
  44.      case 'S':  res=QStreamOp(session, keyword, data, dataLen); break;
  45.      case 'r':  res=QRenameOp(session, keyword, data);       break;
  46.      case 'D':  res=QDebugOp(session, keyword);              break;
  47.      case 'g':  res=QGetOp(session, keyword, -1);            break;
  48.      case 'd':  res=QDeleteOp(session, keyword);             break;
  49.      case 'i':  res=QInfoOp(session);                        break;
  50.      case 'c':  res=QSubscribeOp(session, keyword, -1);      break;
  51.      case 'k':  res=QClearSubscriptionsOp(session,atoi(keyword)); break;
  52.      case 'p':  res=QPingOp(session);                        break;
  53.      default:   printf("Command code %c was not recognized.\n",debugline[0]); break;
  54.    }
  55.    printf("(Op result was %i)\n",res);
  56.    if (debugline[0] == '\0') return;
  57.   }
  58. }
  59.  
  60.  
  61. void CleanExit(void)
  62. {
  63. printf("\nCleaning up...\n");
  64.   if (session)      QFreeSession(session);        /* This MUST be done before we close the library! */
  65.   if (AMarqueeBase) CloseLibrary(AMarqueeBase);  
  66.   printf("All done.\n");
  67. }
  68.  
  69. /* Main program */
  70. int main(int argc, char ** argv)
  71. {
  72.   char * connectTo, * progName;
  73.   int port;
  74.     
  75.   printf("Usage Note:  AMarqueeDebug [hostname=localhost] [myname=debug] [port=2957]\n");  
  76.   atexit(CleanExit);
  77.   
  78.   connectTo = (argc>1) ? argv[1] : "localhost";
  79.   progName  = (argc>2) ? argv[2] : "debug";
  80.   port      = (argc>3) ? atoi(argv[3]) : 2957;
  81.  
  82.   if ((AMarqueeBase = OpenLibrary("amarquee.library",41L)) == NULL)
  83.   {
  84.     printf("Couldn't open amarquee.library v41!\n");
  85.     exit(RETURN_ERROR);
  86.   }
  87.   printf("Connecting to %s:%i\n",connectTo, port);
  88.  
  89. #ifdef ASYNC_CONNECT
  90.   if ((session = QNewSessionAsync(connectTo, port, progName)) == NULL)
  91.   {
  92.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  93.     exit(RETURN_WARN);
  94.   }
  95. #else
  96.   if ((session = QNewSession(connectTo, port, progName)) == NULL)
  97.   {
  98.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  99.     exit(RETURN_WARN);
  100.   }
  101. #endif
  102.  
  103.   printf("Connected to server %s:%i\n",connectTo, port);
  104.  
  105.   /* Setup some sample data */
  106. /*
  107.   (void)QSetOp(session, "sampledata",             "Kids",    5);
  108.   (void)QSetOp(session, "sampledata/Jeremy",      "1",       2);
  109.   (void)QSetOp(session, "sampledata/Joanna",      "2",       2);
  110.   (void)QSetOp(session, "sampledata/Joanna/nerd", "yep! :)", 8);
  111.   (void)QSetOp(session, "sampledata/Joellen",     "3",       2);
  112.   (void)QSetOp(session, "sampledata/Charcoal",    "Kitty!",  7);
  113.   (void)QGo(session, 0L);
  114. */
  115.  
  116.   printf("Commands are:\n");
  117.   printf("\n");
  118.   printf("a wildhostpath   Access control (default is /#?/#?)\n");
  119.   printf("A wildhostpath   Access control for incoming messages (default in no access)\n");
  120.   printf("m hosts=data     Send an active message to hosts\n");
  121.   printf("s path=data      Set data node value\n");
  122.   printf("S path=data      Stream data node value\n");
  123.   printf("r path=newlabel  Rename data node\n");
  124.   printf("D debugstring    Send debug string\n");
  125.   printf("g wildpath       Get a node or nodes\n");
  126.   printf("c wildpath       Subscribe to a node or nodes\n");
  127.   printf("k opID           Klear subscriptions (by id or 0 for all)\n");
  128.   printf("d wildpath       Delete a node or nodes\n");
  129.   printf("i                Request info packet\n");
  130.   printf("p                Request ping packet\n");
  131.   printf("<enter>          Send accumulated transactions (GO!!)\n");
  132.   printf("\n");
  133.   printf("Press CTRL-F to enter commands, or CTRL-C to quit\n");
  134.   
  135.   while(1)
  136.   {
  137.     struct QMessage * qMsg;
  138.     ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C) | (SIGBREAKF_CTRL_F);
  139.  
  140.     /* Wait for next message from the server */
  141.     signals = Wait(signals);
  142.     
  143.     if (signals & (1L << session->qMsgPort->mp_SigBit))
  144.     {
  145.       while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
  146.       {
  147.         struct QRunInfo * inf = (qMsg->qm_DataLen == sizeof(struct QRunInfo)) ? ((struct QRunInfo *) qMsg->qm_Data) : NULL;
  148.  
  149.         /* Handle message */
  150.         printf("Message %p recieved---------\n",qMsg);
  151.         printf("Status:       %i\n",  qMsg->qm_Status);
  152.         printf("Error Line:   %i\n",  qMsg->qm_ErrorLine);
  153.         printf("Message ID:   %i\n",  qMsg->qm_ID);
  154.         printf("Path:        [%s]\n", qMsg->qm_Path?qMsg->qm_Path:"<NULL>");
  155.         printf("Data:        [%s](int=%i)\n", qMsg->qm_Data?qMsg->qm_Data:((UBYTE*)"<NULL>"),qMsg->qm_Data?(*((int*)qMsg->qm_Data)):0);
  156.         printf("DataLen:      %lu\n", qMsg->qm_DataLen);
  157.         printf("ActualLen:    %lu\n", qMsg->qm_ActualLen);
  158.  
  159.         if (inf) printf("Info: alloced:%li allowed:%li avail:%li\n",inf->qr_Alloced, inf->qr_Allowed, inf->qr_Avail); 
  160.         FreeQMessage(session, qMsg);
  161.       }
  162.     }
  163.     if (signals & SIGBREAKF_CTRL_F) ProcessDebugCommands(session);
  164.     if (signals & SIGBREAKF_CTRL_C) break;  /* Quit if CTRL-C pressed */
  165.   }
  166.   /* CleanExit() called here! */
  167. }
  168.